package cn.rokka.rbac.service.impl;


import cn.rokka.rbac.domain.Department;
import cn.rokka.rbac.mapper.DepartmentMapper;
import cn.rokka.rbac.qo.QueryObject;
import cn.rokka.rbac.service.IDepartmentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public void delete(Long id) {
        departmentMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void save(Department record) {
        departmentMapper.insert(record);
    }

    @Override
    public Department getById(Long id) {
        return departmentMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Department> listAll() {
        return departmentMapper.selectAll();
    }

    @Override
    public void update(Department record) {
        departmentMapper.updateByPrimaryKey(record);
    }

    @Override
    public PageInfo<Department> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        return new PageInfo<>(departmentMapper.selectForList(qo));
    }
}
